﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.LotUI {
    import flash.events.*;
    import flash.display.*;
    import Classes.sim.*;
    import Display.FactoryUI.*;

    public class SlidePickGroup extends Sprite {

        protected const PICK_OFFSET_X:Number = 5;
        protected const PICK_OFFSET_Y:Number = -5;

        protected var m_lotManager:LotManager;
        protected var m_picks:Array;
        protected var m_isFirstClicked:Boolean = false;
        protected var m_isTopSlidePickOpened:Boolean = false;

        public function SlidePickGroup(_arg1:LotManager, _arg2:Array=null, _arg3:Boolean=false){
            this.m_lotManager = _arg1;
            this.m_picks = ((_arg2) || ([]));
            if (_arg3){
                this.init();
            };
            addEventListener(MouseEvent.CLICK, this.onClick);
        }
        public function get numPicks():int{
            return ((this.m_picks) ? this.m_picks.length : 0);
        }
        public function get isTopSlidePickOpened():Boolean{
            return (this.m_isTopSlidePickOpened);
        }
        public function init():void{
            this.draw();
            this.addListeners();
        }
        public function isInGroup(_arg1:SlidePick):Boolean{
            var _local2:int = this.m_picks.indexOf(_arg1);
            var _local3:Boolean = Boolean((_local2 >= 0));
            return (_local3);
        }
        public function getPickByPropValue(_arg1:String, _arg2):SlidePick{
            var _local3:SlidePick;
            var _local4:SlidePick;
            for each (_local4 in this.m_picks) {
                if (((_local4.hasOwnProperty(_arg1)) && ((_local4[_arg1] == _arg2)))){
                    _local3 = _local4;
                    break;
                };
            };
            return (_local3);
        }
        public function addPick(_arg1:SlidePick):void{
            this.m_picks[this.m_picks.length] = _arg1;
        }
        public function removePick(_arg1:SlidePick):void{
            var _local2:int = this.m_picks.indexOf(_arg1);
            if (_local2 >= 0){
                this.m_picks.splice(_local2, 1);
            };
            if (_arg1.parent == this){
                _arg1.parent.removeChild(_arg1);
            };
        }
        public function redraw():void{
            this.draw();
            this.m_isTopSlidePickOpened = false;
            if (((this.m_picks) && ((this.m_picks.length > 1)))){
                if (this.m_isTopSlidePickOpened){
                    this.openTopSlidePick();
                } else {
                    this.closeTopSlidePick();
                };
            };
        }
        public function cleanUp():void{
            this.removeListeners();
            this.m_picks = null;
            this.m_lotManager = null;
        }
        public function getTopPick():SlidePick{
            return ((this.numPicks) ? this.m_picks[0] : null);
        }
        public function onClick():void{
            if (this.m_isTopSlidePickOpened){
                this.closeTopSlidePick();
            } else {
                this.openTopSlidePick();
            };
        }
        protected function draw():void{
            var _local3:SlidePick;
            var _local1:Number = 0;
            var _local2:Number = 0;
            for each (_local3 in this.m_picks) {
                _local3.x = _local1;
                _local3.y = _local2;
                addChildAt(_local3, 0);
                _local1 = (_local1 + this.PICK_OFFSET_X);
                _local2 = (_local2 + this.PICK_OFFSET_Y);
            };
        }
        protected function openTopSlidePick():void{
            var _local1:SlidePick;
            var _local2:LotSlidePick;
            if (this.m_picks.length){
                _local1 = this.getTopPick();
                if ((_local1 is LotSlidePick)){
                    _local2 = (_local1 as LotSlidePick);
                    _local2.openInnerPane();
                    this.m_isTopSlidePickOpened = true;
                };
            };
        }
        protected function closeTopSlidePick():void{
            var _local1:SlidePick;
            var _local2:LotSlidePick;
            if (this.m_picks.length){
                _local1 = this.getTopPick();
                if ((_local1 is LotSlidePick)){
                    _local2 = (_local1 as LotSlidePick);
                    _local2.closeInnerPane();
                    this.m_isTopSlidePickOpened = false;
                };
            };
        }
        protected function addListeners():void{
            addEventListener(MouseEvent.CLICK, this.mouseClickHandler, false, 0, true);
        }
        protected function removeListeners():void{
            removeEventListener(MouseEvent.CLICK, this.mouseClickHandler);
        }
        protected function mouseClickHandler(_arg1:MouseEvent):void{
            this.onClick();
        }

    }
}//package Display.LotUI 
